export function generateRandomKey() {
  // 大写字母
  const uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  // 小写字母
  const lowercaseLetters = "abcdefghijklmnopqrstuvwxyz";
  // 数字
  const numbers = "0123456789";
  // 特殊字符
  const specialCharacters = "!@#$%^&*()";
  const allCharacters =
    uppercaseLetters + lowercaseLetters + numbers + specialCharacters;
  // 生成8到20之间的随机长度
  const length = Math.floor(Math.random() * (20 - 8 + 1)) + 8;
  let randomKey = "";
  // 添加至少一个大写字母
  randomKey +=
    uppercaseLetters[Math.floor(Math.random() * uppercaseLetters.length)];
  // 添加至少一个小写字母
  randomKey +=
    lowercaseLetters[Math.floor(Math.random() * lowercaseLetters.length)];
  // 添加至少一个数字
  randomKey += numbers[Math.floor(Math.random() * numbers.length)];
  // 添加至少一个特殊字符
  randomKey +=
    specialCharacters[Math.floor(Math.random() * specialCharacters.length)];
  // 生成余下的随机字符
  for (let i = 0; i < length - 4; i++) {
    const randomIndex = Math.floor(Math.random() * allCharacters.length);
    randomKey += allCharacters[randomIndex];
  }
  // 对随机密钥进行随机排序
  randomKey = randomKey
    .split("")
    .sort(() => Math.random() - 0.5)
    .join("");
  return randomKey;
}

export function getDaysInMonth(val?: any) {
  let date;
  val ? (date = new Date(val)) : (date = new Date());
  // console.log(date);
  let new_year = date.getFullYear();
  const month = date.getMonth();
  let new_month = month + 1;
  let mon;
  let day;
  if (month > 12) {
    new_month -= 12;
    new_year++;
  }
  // 第一天
  const firstDay = new Date(new_year, new_month, 1);
  // 最后一天
  const lastDay = new Date(firstDay.getTime() - 1000 * 60 * 60 * 24).getDate();
  if (new_month < 10) {
    mon = "0" + new_month;
  } else {
    mon = new_month;
  }
  if (lastDay < 10) {
    day = "0" + lastDay;
  } else {
    day = lastDay;
  }
  return [
    new_year + "-" + mon + "-" + "0" + firstDay.getDate(),
    // 选择月份的最后一天
    new_year + "-" + mon + "-" + day,
  ];
}

